<div class="tmd-doc">
<h1 class="tmd-header-1">
Basic Types and Basic Value Literals
</h1>
<p></p>
<div class="tmd-usual">
Types can be viewed as value templates, and values can be viewed as type instances. This article will introduce the built-in basic types and their value literals in Go. Composite types will not get introduced in this article.
</div>
<p></p>
<h3 id="overview" class="tmd-header-3">
Built-in Basic Types in Go
</h3>
<p></p>
<div class="tmd-usual">
Go supports following built-in basic types:
</div>
<ul class="tmd-list">
<li class="tmd-list-item">
<div class="tmd-usual">
one boolean built-in boolean type: <code class="tmd-code-span">bool</code>.
</div>
</li>
<li class="tmd-list-item">
<div class="tmd-usual">
11 built-in integer numeric types (basic integer types): <code class="tmd-code-span">int8</code>, <code class="tmd-code-span">uint8</code>, <code class="tmd-code-span">int16</code>, <code class="tmd-code-span">uint16</code>, <code class="tmd-code-span">int32</code>, <code class="tmd-code-span">uint32</code>, <code class="tmd-code-span">int64</code>, <code class="tmd-code-span">uint64</code>, <code class="tmd-code-span">int</code>, <code class="tmd-code-span">uint</code>, and <code class="tmd-code-span">uintptr</code>.
</div>
</li>
<li class="tmd-list-item">
<div class="tmd-usual">
two built-in floating-point numeric types: <code class="tmd-code-span">float32</code> and <code class="tmd-code-span">float64</code>.
</div>
</li>
<li class="tmd-list-item">
<div class="tmd-usual">
two built-in complex numeric types: <code class="tmd-code-span">complex64</code> and <code class="tmd-code-span">complex128</code>.
</div>
</li>
<li class="tmd-list-item">
<div class="tmd-usual">
one built-in string type: <code class="tmd-code-span">string</code>.
</div>
</li>
</ul>
<p></p>
<div class="tmd-usual">
Each of the 17 built-in basic types belongs to one different kind of type in Go. We can use the above built-in types in code without importing any packages, though all the names of these types are non-exported identifiers.
</div>
<p></p>
<div class="tmd-usual">
15 of the 17 built-in basic types are numeric types. Numeric types include integer types, floating-point types and complex types.
</div>
<p></p>
<div class="tmd-usual">
Go also support two built-in type aliases,
</div>
<ul class="tmd-list">
<li class="tmd-list-item">
<div class="tmd-usual">
<code class="tmd-code-span">byte</code> is a built-in alias of <code class="tmd-code-span">uint8</code>. We can view <code class="tmd-code-span">byte</code> and <code class="tmd-code-span">uint8</code> as the same type.
</div>
</li>
<li class="tmd-list-item">
<div class="tmd-usual">
<code class="tmd-code-span">rune</code> is a built-in alias of <code class="tmd-code-span">int32</code>. We can view <code class="tmd-code-span">rune</code> and <code class="tmd-code-span">int32</code> as the same type.
</div>
</li>
</ul>
<p></p>
<div class="tmd-usual">
The integer types whose names starting with an <code class="tmd-code-span">u</code> are unsigned types. Values of unsigned types are always non-negative. The number in the name of a type means how many binary bits a value of the type will occupy in memory at run time. For example, every value of the <code class="tmd-code-span">uint8</code> occupies 8 bits in memory. So the largest <code class="tmd-code-span">uint8</code> value is <code class="tmd-code-span">255</code> (2<sup>8</sup>-1), the largest <code class="tmd-code-span">int8</code> value is <code class="tmd-code-span">127</code> (2<sup>7</sup>-1), and the smallest <code class="tmd-code-span">int8</code> value is <code class="tmd-code-span">-128</code> (-2<sup>7</sup>).
</div>
<p></p>
<div class="tmd-usual">
If a value occupies <span class="tmd-bold">N</span> bits in memory, we say the size of the value is <span class="tmd-bold">N</span> bits. The sizes of all values of a type are always the same, so value sizes are often called as type sizes.
</div>
<p></p>
<div class="tmd-usual">
We often measure the size of a value based on the number of bytes it occupies in memory. One byte contains 8 bits. So the size of the <code class="tmd-code-span">uint32</code> type is four bytes.
</div>
<p></p>
<div class="tmd-usual">
The size of <code class="tmd-code-span">uintptr</code>, <code class="tmd-code-span">int</code> and <code class="tmd-code-span">uint</code> values n memory are implementation-specific. Generally, The size of <code class="tmd-code-span">int</code> and <code class="tmd-code-span">uint</code> values are 4 bytes on 32-bit architectures, and 8 bytes on 64-bit architectures. The size of <code class="tmd-code-span">uintptr</code> value must be large enough to store the uninterpreted bits of any memory address.
</div>
<p></p>
<div class="tmd-usual">
The real and imaginary parts of a <code class="tmd-code-span">complex64</code> value are both <code class="tmd-code-span">float32</code> values, and the real and imaginary parts of a <code class="tmd-code-span">complex128</code> value are both <code class="tmd-code-span">float64</code> values.
</div>
<p></p>
<div class="tmd-usual">
In memory, all floating-point numeric values in Go are stored in <a href="https://en.wikipedia.org/wiki/IEEE_754">IEEE-754 format</a>.
</div>
<p></p>
<p></p>
<div class="tmd-usual">
A boolean value represents a truth. There are only two possible boolean values in memory, they are denoted by the two predeclared named constants, <code class="tmd-code-span">false</code> and <code class="tmd-code-span">true</code>. Name constants will be introduced in <a href="constants-and-variables.html">the next article</a>.
</div>
<p></p>
<p></p>
<div class="tmd-usual">
In logic, a string value denotes a piece of text. In memory, a string value stores a sequence of bytes, which is the UTF-8 encoding representation of the piece of text denoted by the string value. We can learn more facts on strings from the article <a href="string.html">strings in Go</a> later.
</div>
<p></p>
<p></p>
<div class="tmd-usual">
Although there is only one built-in type for each of boolean and string types, we can define custom boolean and string types for the built-in boolean and string types. So there can be many boolean and string types. The same is for any kinds of numeric types. The following are some type declaration examples. In these declarations, the word <code class="tmd-code-span">type</code> is a keyword.
</div>
<p></p>
<pre class="tmd-code line-numbers">
<code class="language-go">/* Some type definition declarations */

// status and bool are two different types.
type status bool
// MyString and string are two different types.
type MyString string
// Id and uint64 are two different types.
type Id uint64
// real and float32 are two different types.
type real float32

/* Some type alias declarations */

// boolean and bool denote the same type.
type boolean = bool
// Text and string denote the same type.
type Text = string
// U8, uint8 and byte denote the same type.
type U8 = uint8
// char, rune and int32 denote the same type.
type char = rune
</code></pre>
<p></p>
<div class="tmd-usual">
We can call the custom <code class="tmd-code-span">real</code> type defined above and the built-in <code class="tmd-code-span">float32</code> type both as float32 types. Note, the second <span class="tmd-bold"><span class="tmd-italic">float32</span></span> word in the last sentence is a general reference, whereas the first one is a specified reference. Similarly, <code class="tmd-code-span">MyString</code> and <code class="tmd-code-span">string</code> are both string types, <code class="tmd-code-span">status</code> and <code class="tmd-code-span">bool</code> are both bool types, etc.
</div>
<p></p>
<div class="tmd-usual">
We can learn more on custom types in the article <a href="type-system-overview.html">Go type system overview</a> later.
</div>
<p></p>
<p></p>
<h3 class="tmd-header-3">
Zero Values
</h3>
<p></p>
<div class="tmd-usual">
Each type has a zero value. The zero value of a type can be viewed as the default value of the type.
</div>
<ul class="tmd-list">
<li class="tmd-list-item">
<div class="tmd-usual">
The zero value of a boolean type is false.
</div>
</li>
<li class="tmd-list-item">
<div class="tmd-usual">
The zero value of a numeric type is zero, though zeros of different numeric types may have different sizes in memory.
</div>
</li>
<li class="tmd-list-item">
<div class="tmd-usual">
The zero value of a string type is an empty string.
</div>
</li>
</ul>
<p></p>
<h3 id="basic-value-literals" class="tmd-header-3">
Basic Value Literals
</h3>
<p></p>
<div class="tmd-usual">
A literal of a value is a text representation of the value in code. A value may have many literals. The literals denoting values of basic types are called basic value literals.
</div>
<p></p>
<h4 class="tmd-header-4">
Boolean value literals
</h4>
<p></p>
<div class="tmd-usual">
Go specification doesn't define boolean literals. However, in general programming, we can view the two predeclared identifiers, <code class="tmd-code-span">false</code> and <code class="tmd-code-span">true</code>, as boolean literals. But we should know that the two are not literals in the strict sense.
</div>
<p></p>
<div class="tmd-usual">
As mentioned above, zero values of boolean types are denoted with the predeclared <code class="tmd-code-span">false</code> constant.
</div>
<p></p>
<h4 class="tmd-header-4">
Integer value literals
</h4>
<p></p>
<div class="tmd-usual">
There are four integer value literal forms, the decimal (base 10) form, the octal (base 8) form, the hex (base 16) form and the binary form (base 2). For example, the following four integer literals all denote <code class="tmd-code-span">15</code> in decimal.
</div>
<p></p>
<pre class="tmd-code disable-line-numbers111">
<code class="language-go">0xF // the hex form (starts with a "0x" or "0X")
0XF

017 // the octal form (starts with a "0", "0o" or "0O")
0o17
0O17

0b1111 // the binary form (starts with a "0b" or "0B")
0B1111

15 // the decimal form (starts without a "0")
</code></pre>
<p></p>
<div class="tmd-usual">
(Note: the binary form and the octal from starting with <code class="tmd-code-span">0o</code> or <code class="tmd-code-span">0O</code> are supported since Go 1.13.)
</div>
<p></p>
<div class="tmd-usual">
The following program will print two <code class="tmd-code-span">true</code> texts.
</div>
<pre class="tmd-code line-numbers">
<code class="language-go">package main

func main() {
	println(15 == 017) // true
	println(15 == 0xF) // true
}
</code></pre>
<p></p>
<div class="tmd-usual">
Note, the two <code class="tmd-code-span">==</code> are the equal-to comparison operator, which will be introduced in <a href="operators.html">common operators</a>.
</div>
<p></p>
<p></p>
<div class="tmd-usual">
Generally, zero values of integer types are denoted as <code class="tmd-code-span">0</code> in literal, though there are many other legal literals for integer zero values, such as <code class="tmd-code-span">00</code> and <code class="tmd-code-span">0x0</code>. In fact, the zero value literals introduced in the current article for other kinds of numeric types can also represent the zero value of any integer type.
</div>
<p></p>
<h4 class="tmd-header-4">
Floating-point value literals
</h4>
<p></p>
<div class="tmd-usual">
A decimal floating-point value literal may contain a decimal integer part, a decimal point, a decimal fractional part, and an integer exponent part (10-based). Such an integer exponent part starts with a letter <code class="tmd-code-span">e</code> or <code class="tmd-code-span">E</code> and suffixes with a decimal integer literal (<code class="tmd-code-span">xEn</code> is equivalent to <code class="tmd-code-span">x</code> is multiplied by <code class="tmd-mono-font">10<sup>n</sup></code>, and <code class="tmd-code-span">xE-n</code> is equivalent to <code class="tmd-code-span">x</code> is divided by <code class="tmd-mono-font">10<sup>n</sup></code>). Some examples:
</div>
<pre class="tmd-code disable-line-numbers111">
<code class="language-go">1.23
01.23 // == 1.23
.23
1.
// An "e" or "E" starts the exponent part (10-based).
1.23e2  // == 123.0
123E2   // == 12300.0
123.E+2 // == 12300.0
1e-1    // == 0.1
.1e0    // == 0.1
0010e-2 // == 0.1
0e+5    // == 0.0
</code></pre>
<p></p>
<div class="tmd-usual">
Since Go 1.13, Go also supports another floating point literal form: hexadecimal floating point literal form.
</div>
<ul class="tmd-list">
<li class="tmd-list-item">
<div class="tmd-usual">
A hexadecimal floating point literal must end with 2-based exponent part, which starts with a letter <code class="tmd-code-span">p</code> or <code class="tmd-code-span">P</code> and suffixes with a decimal integer literal (<code class="tmd-code-span">yPn</code> is equivalent to <code class="tmd-code-span">y</code> is multiplied by <code class="tmd-mono-font">2<sup>n</sup></code>, and <code class="tmd-code-span">yP-n</code> is equivalent to <code class="tmd-code-span">y</code> is divided by <code class="tmd-mono-font">2<sup>n</sup></code>).
</div>
</li>
<li class="tmd-list-item">
<div class="tmd-usual">
Same as hex integer literals, a hexadecimal floating point literal also must start with <code class="tmd-code-span">0x</code> or <code class="tmd-code-span">0X</code>. Different from hex integer literals, a hexadecimal floating point literal may contain a radix point and a hexadecimal fractional part.
</div>
</li>
</ul>
<p></p>
<div class="tmd-usual">
The followings are some legal hexadecimal floating point literals:
</div>
<pre class="tmd-code disable-line-numbers111">
<code class="language-go">0x1p-2     // == 1.0/4 = 0.25
0x2.p10    // == 2.0 * 1024 == 2048.0
0x1.Fp+0   // == 1+15.0/16 == 1.9375
0X.8p1     // == 8.0/16 * 2 == 1.0
0X1FFFP-16 // == 0.1249847412109375
</code></pre>
<p></p>
<div class="tmd-usual">
However, the following ones are illegal:
</div>
<pre class="tmd-code disable-line-numbers111">
<code class="language-go">0x.p1    // mantissa has no digits
1p-2     // p exponent requires hexadecimal mantissa
0x1.5e-2 // hexadecimal mantissa requires p exponent
</code></pre>
<p></p>
<div class="tmd-usual">
Note: the following literal is legal, but it is not a floating point literal. It is a subtraction arithmetic expression actually. The <code class="tmd-code-span">e</code> in it means <code class="tmd-code-span">14</code> in decimal. <code class="tmd-code-span">0x15e</code> is a hex integer literal, <code class="tmd-code-span">-</code> is the subtraction operator, and <code class="tmd-code-span">2</code> is a decimal integer literal. (Arithmetic operators will be introduced in the article <a href="operators.html">common operators</a>.)
</div>
<p></p>
<p></p>
<pre class="tmd-code disable-line-numbers111">
<code class="language-go">0x15e-2 // == 0x15e - 2 // a subtraction expression
</code></pre>
<p></p>
<div class="tmd-usual">
The standard literals for zero value of floating-point types are <code class="tmd-code-span">0.0</code>, though there are many other legal literals, such as <code class="tmd-code-span">0.</code>, <code class="tmd-code-span">.0</code>, <code class="tmd-code-span">0e0</code>, <code class="tmd-code-span">0x0p0</code>, etc. In fact, the zero value literals introduced in the current article for other kinds of numeric types can also represent the zero value of any floating-point type.
</div>
<p></p>
<h4 class="tmd-header-4">
Imaginary value literals
</h4>
<p></p>
<div class="tmd-usual">
An imaginary literal consists of a floating-point or integer literal and a lower-case letter <code class="tmd-code-span">i</code>. Examples:
</div>
<pre class="tmd-code disable-line-numbers111">
<code class="language-go">1.23i
1.i
.23i
123i
0123i   // == 123i (for backward-compatibility. See below.)
1.23E2i // == 123i
1e-1i
011i   // == 11i (for backward-compatibility. See below.)
00011i // == 11i (for backward-compatibility. See below.)
// The following lines only compile okay since Go 1.13.
0o11i    // == 9i
0x11i    // == 17i
0b11i    // == 3i
0X.8p-0i // == 0.5i
</code></pre>
<p></p>
<div class="tmd-usual">
Note, before Go 1.13, in an imaginary literal, the letter <code class="tmd-code-span">i</code> can only be prefixed with a floating-point literal. To be compatible with the older versions, since Go 1.13, the integer literals appearing as octal integer forms not starting with <code class="tmd-code-span">0o</code> and <code class="tmd-code-span">0O</code> are still viewed as floating-point literals, such as <code class="tmd-code-span">011i</code>, <code class="tmd-code-span">0123i</code> and <code class="tmd-code-span">00011i</code> in the above example.
</div>
<p></p>
<div class="tmd-usual">
Imaginary literals are used to represent the imaginary parts of complex values. Here are some literals to denote complex values:
</div>
<pre class="tmd-code disable-line-numbers111">
<code class="language-go">1 + 2i       // == 1.0 + 2.0i
1. - .1i     // == 1.0 + -0.1i
1.23i - 7.89 // == -7.89 + 1.23i
1.23i        // == 0.0 + 1.23i
</code></pre>
<p></p>
<div class="tmd-usual">
The standard literals for zero values of complex types are <code class="tmd-code-span">0.0+0.0i</code>, though there are many other legal literals, such as <code class="tmd-code-span">0i</code>, <code class="tmd-code-span">.0i</code>, <code class="tmd-code-span">0+0i</code>, etc. In fact, the zero value literals introduced in the current article for other kinds of numeric types can also represent the zero value of any complex type.
</div>
<p></p>
<h4 id="underscores-in-literals" class="tmd-header-4">
Use <code class="tmd-code-span">_</code> in numeric literals for better readability
</h4>
<p></p>
<div class="tmd-usual">
Since Go 1.13, underscores <code class="tmd-code-span">_</code> can appear in integer, floating-point and imaginary literals as digit separators to enhance code readability. But please note, in a numeric literal,
</div>
<ul class="tmd-list">
<li class="tmd-list-item">
<div class="tmd-usual">
any <code class="tmd-code-span">_</code> is not allowed to be used as the first or the last character of the literal,
</div>
</li>
<li class="tmd-list-item">
<div class="tmd-usual">
the two sides of any <code class="tmd-code-span">_</code> must be either literal prefixes (such as <code class="tmd-code-span">0X</code>) or legal digit characters.
</div>
</li>
</ul>
<p></p>
<div class="tmd-usual">
Some legal and illegal numeric literals which contain underscores:
</div>
<p></p>
<pre class="tmd-code disable-line-numbers111">
<code class="language-go">// Legal ones:
6_9          // == 69
0_33_77_22   // == 0337722
0x_Bad_Face  // == 0xBadFace
0X_1F_FFP-16 // == 0X1FFFP-16
0b1011_0111 + 0xA_B.Fp2i

// Illegal ones:
_69        // _ can't appear as the first character
69_        // _ can't appear as the last character
6__9       // one side of _ is a illegal character
0_xBadFace // "x" is not a legal octal digit
1_.5       // "." is not a legal octal digit
1._5       // "." is not a legal octal digit
</code></pre>
<p></p>
<h4 id="rune" class="tmd-header-4">
Rune value literals
</h4>
<p></p>
<div class="tmd-usual">
Rune types, including custom defined rune types and the built-in <code class="tmd-code-span">rune</code> type (a.k.a., <code class="tmd-code-span">int32</code> type), are special integer types, so all rune values can be denoted by the integer literals introduced above. On the other hand, many values of all kinds of integer types can also be represented by rune literals introduced below in the current subsection.
</div>
<p></p>
<div class="tmd-usual">
A rune value is intended to store a Unicode code point. Generally, we can view a code point as a Unicode character, but we should know that some Unicode characters are composed of more than one code points each.
</div>
<p></p>
<div class="tmd-usual">
A rune literal is expressed as one or more characters enclosed in a pair of quotes. The enclosed characters denote one Unicode code point value. There are some minor variants of the rune literal form. The most popular form of rune literals is just to enclose the characters denoted by rune values between two single quotes. For example
</div>
<pre class="tmd-code disable-line-numbers111">
<code class="language-go">'a' // an English character
'π'
'众' // a Chinese character
</code></pre>
<p></p>
<div class="tmd-usual">
The following rune literal variants are equivalent to <code class="tmd-code-span">'a'</code> (the Unicode value of character <code class="tmd-code-span">a</code> is 97).
</div>
<pre class="tmd-code disable-line-numbers111">
<code class="language-go">// 141 is the octal representation of decimal number 97.
'\141'
// 61 is the hex representation of decimal number 97.
'\x61'
'\u0061'
'\U00000061'
</code></pre>
<p></p>
<div class="tmd-usual">
Please note, <code class="tmd-code-span">\</code> must be followed by exactly three octal digits to represent a byte value, <code class="tmd-code-span">\x</code> must be followed by exactly two hex digits to represent a byte value, <code class="tmd-code-span">\u</code> must be followed by exactly four hex digits to represent a rune value, and <code class="tmd-code-span">\U</code> must be followed by exactly eight hex digits to represent a rune value. Each such octal or hex digit sequence must represent a legal Unicode code point, otherwise, it fails to compile.
</div>
<p></p>
<div class="tmd-usual">
The following program will print 7 <code class="tmd-code-span">true</code> texts.
</div>
<pre class="tmd-code line-numbers">
<code class="language-go">package main

func main() {
	println('a' == 97)
	println('a' == '\141')
	println('a' == '\x61')
	println('a' == '\u0061')
	println('a' == '\U00000061')
	println(0x61 == '\x61')
	println('\u4f17' == '众')
}
</code></pre>
<p></p>
<div class="tmd-usual">
In fact, the four variant rune literal forms just mentioned are rarely used for rune values in practice. They are occasionally used in interpreted string literals (see the next subsection for details).
</div>
<p></p>
<div class="tmd-usual">
If a rune literal is composed by two characters (not including the two quotes), the first one is the character <code class="tmd-code-span">\</code> and the second one is not a digital character, <code class="tmd-code-span">x</code>, <code class="tmd-code-span">u</code> and <code class="tmd-code-span">U</code>, then the two successive characters will be escaped as one special character. The possible character pairs to be escaped are:
</div>
<pre class="tmd-code disable-line-numbers111">
<code class="language-go">\a   (Unicode value 0x07) alert or bell
\b   (Unicode value 0x08) backspace
\f   (Unicode value 0x0C) form feed
\n   (Unicode value 0x0A) line feed or newline
\r   (Unicode value 0x0D) carriage return
\t   (Unicode value 0x09) horizontal tab
\v   (Unicode value 0x0b) vertical tab
\\   (Unicode value 0x5c) backslash
\'   (Unicode value 0x27) single quote
</code></pre>
<p></p>
<div class="tmd-usual">
<code class="tmd-code-span">\n</code> is the most used escape character pair.
</div>
<p></p>
<div class="tmd-usual">
An example:
</div>
<pre class="tmd-code line-numbers">
<code class="language-go">    println('\n') // 10
    println('\r') // 13
    println('\'') // 39

    println('\n' == 10)     // true
    println('\n' == '\x0A') // true
</code></pre>
<p></p>
<div class="tmd-usual">
There are many literals which can denote the zero values of rune types, such as <code class="tmd-code-span">'\000'</code>, <code class="tmd-code-span">'\x00'</code>, <code class="tmd-code-span">'\u0000'</code>, etc. In fact, we can also use any numeric literal introduced above to represent the values of rune types, such as <code class="tmd-code-span">0</code>, <code class="tmd-code-span">0x0</code>, <code class="tmd-code-span">0.0</code>, <code class="tmd-code-span">0e0</code>, <code class="tmd-code-span">0i</code>, etc.
</div>
<p></p>
<h4 id="string-literals" class="tmd-header-4">
String value literals
</h4>
<p></p>
<div class="tmd-usual">
String values in Go are UTF-8 encoded. In fact, all Go source files must be UTF-8 encoding compatible.
</div>
<p></p>
<div class="tmd-usual">
There are two forms of string value literals, interpreted string literal (double quotes form) and raw string literal (back quotes form). For example, the following two string literals are equivalent:
</div>
<p></p>
<pre class="tmd-code disable-line-numbers111">
<code class="language-go">// The interpreted form.
"Hello\nworld!\n\"你好世界\""

// The raw form.
`Hello
world!
"你好世界"`
</code></pre>
<p></p>
<div class="tmd-usual">
In the above interpreted string literal, each <code class="tmd-code-span">\n</code> character pair will be escaped as one newline character, and each <code class="tmd-code-span">\"</code> character pair will be escaped as one double quote character. Most of such escape character pairs are the same as the escape character pairs used in rune literals introduced above, except that <code class="tmd-code-span">\"</code> is only legal in interpreted string literals and <code class="tmd-code-span">\`</code> is only legal in rune literals.
</div>
<p></p>
<div class="tmd-usual">
The character sequence of <code class="tmd-code-span">\</code>, <code class="tmd-code-span">\x</code>, <code class="tmd-code-span">\u</code> and <code class="tmd-code-span">\U</code> followed by several octal or hex digits introduced in the last section can also be used in interpreted string literals.
</div>
<p></p>
<pre class="tmd-code disable-line-numbers111">
<code class="language-go">// The following interpreted string literals are equivalent.
"\141\142\143"
"\x61\x62\x63"
"\x61b\x63"
"abc"

// The following interpreted string literals are equivalent.
"\u4f17\xe4\xba\xba"
      // The Unicode of 众 is 4f17, which is
      // UTF-8 encoded as three bytes: e4 bc 97.
"\xe4\xbc\x97\u4eba"
      // The Unicode of 人 is 4eba, which is
      // UTF-8 encoded as three bytes: e4 ba ba.
"\xe4\xbc\x97\xe4\xba\xba"
"众人"
</code></pre>
<p></p>
<div class="tmd-usual">
Please note that each English character (code point) is represented with one byte, but each Chinese character (code point) is represented with three bytes.
</div>
<p></p>
<div class="tmd-usual">
In a raw string literal, no character sequences will be escaped. The back quote character is not allowed to appear in a raw string literal. To get better cross-platform compatibility, carriage return characters (Unicode code point <code class="tmd-code-span">0x0D</code>) inside raw string literals will be discarded.
</div>
<p></p>
<div class="tmd-usual">
Zero values of string types can be denoted as <code class="tmd-code-span">""</code> or <code class="tmd-code-span">``</code> in literal.
</div>
<p></p>
<h3 id="representability" class="tmd-header-3">
Representability of Basic Numeric Value Literals
</h3>
<p></p>
<div class="tmd-usual">
A numeric literal can be used to represent as an integer value only if it needn't be rounded. For example, <code class="tmd-code-span">1.23e2</code> can represent as values of any basic integer types, but <code class="tmd-code-span">1.23</code> can't represent as values of any basic integer types. Rounding is allowed when using a numeric literal to represent a non-integer basic numeric values.
</div>
<p></p>
<div class="tmd-usual">
Each basic numeric type has a representable value range. So, if a literal overflows the value range of a type, then the literal is not representable as values of the type.
</div>
<p></p>
<div class="tmd-usual">
Some examples:
</div>
<table class="tmd-table">
<tr>
<th>
The Literal
</th>
<th>
Types Which Values the Literal Can Represent
</th>
</tr>
<tr>
<td>
<div class="tmd-usual">
<code class="tmd-code-span">256</code>
</div>
</td>
<td>
<div class="tmd-usual">
All basic numeric types except int8 and uint8 types.
</div>
</td>
</tr>
<tr>
<td>
<div class="tmd-usual">
<code class="tmd-code-span">255</code>
</div>
</td>
<td>
<div class="tmd-usual">
All basic numeric types except int8 types.
</div>
</td>
</tr>
<tr>
<td>
<div class="tmd-usual">
<code class="tmd-code-span">-123</code>
</div>
</td>
<td>
<div class="tmd-usual">
All basic numeric types except the unsigned ones.
</div>
</td>
</tr>
<tr>
<td>
<div class="tmd-usual">
<code class="tmd-code-span">123</code>
</div>
</td>
<td rowspan="5">
<div class="tmd-base tmd-align-center">
<div class="tmd-usual">
All basic numeric types.
</div>
</div>
</td>
</tr>
<tr>
<td>
<div class="tmd-usual">
<code class="tmd-code-span">123.000</code>
</div>
</td>
</tr>
<tr>
<td>
<div class="tmd-usual">
<code class="tmd-code-span">1.23e2</code>
</div>
</td>
</tr>
<tr>
<td>
<div class="tmd-usual">
<code class="tmd-code-span">'a'</code>
</div>
</td>
</tr>
<tr>
<td>
<div class="tmd-usual">
<code class="tmd-code-span">1.0+0i</code>
</div>
</td>
</tr>
<tr>
<td>
<div class="tmd-usual">
<code class="tmd-code-span">1.23</code>
</div>
</td>
<td rowspan="2">
<div class="tmd-base tmd-align-center">
<div class="tmd-usual">
All basic floating-point and complex numeric types.
</div>
</div>
</td>
</tr>
<tr>
<td>
<div class="tmd-usual">
<code class="tmd-code-span">0x10000000000000000</code><br/>(16 zeros)
</div>
</td>
</tr>
<tr>
<td>
<div class="tmd-usual">
<code class="tmd-code-span">3.5e38</code>
</div>
</td>
<td>
<div class="tmd-usual">
All basic floating-point and complex numeric types except float32 and complex64 types.
</div>
</td>
</tr>
<tr>
<td>
<div class="tmd-usual">
<code class="tmd-code-span">1+2i</code>
</div>
</td>
<td>
<div class="tmd-usual">
All basic complex numeric types.
</div>
</td>
</tr>
<tr>
<td>
<div class="tmd-usual">
<code class="tmd-code-span">2e+308</code>
</div>
</td>
<td>
<div class="tmd-usual">
None basic types.
</div>
</td>
</tr>
</table>
<p></p>
<div class="tmd-usual">
Notes:
</div>
<ul class="tmd-list">
<li class="tmd-list-item">
<div class="tmd-usual">
Because no values of the basic integer types provided in Go can hold <code class="tmd-code-span">0x10000000000000000</code>, so the literal is not representable as values of any basic integer types.
</div>
</li>
<li class="tmd-list-item">
<div class="tmd-usual">
The maximum IEEE-754 float32 value which can be represented accurately is <code class="tmd-code-span">3.40282346638528859811704183484516925440e+38</code>, so <code class="tmd-code-span">3.5e38</code> is not representable as values of any float32 and complex64 types.
</div>
</li>
<li class="tmd-list-item">
<div class="tmd-usual">
The max IEEE-754 float64 value which can be represented accurately is <code class="tmd-code-span">1.797693134862315708145274237317043567981e+308</code>, so <code class="tmd-code-span">2e+308</code> is not representable as values of any <code class="tmd-code-span">float64</code> and <code class="tmd-code-span">complex128</code> types.
</div>
</li>
<li class="tmd-list-item">
<div class="tmd-usual">
In the end, please note, although <code class="tmd-code-span">0x10000000000000000</code> can represent values of float32 types, however it can't represent any float32 values accurately in memory. In other words, it will be rounded to the closest float32 value which can be represented accurately in memory when it is used as values of float32 types.
</div>
</li>
</ul>
<p></p>
</div>
